package com.chuantou.yuba.ui;

import android.os.Bundle;
import android.support.v4.view.ViewPager;

import com.chuantou.yuba.R;
import com.chuantou.yuba.adapter.ViewPagerAdapter;
import com.chuantou.yuba.ui.fragment.FansFragment;
import com.chuantou.yuba.ui.fragment.FollowsFragment;
import com.chuantou.yuba.util.Constants;
import com.viewpagerindicator.TabPageIndicator;

public class FriendsActivity extends BaseActionBarActivity {
	protected ViewPager mViewPager;
	protected TabPageIndicator mIndicator;
	private ViewPagerAdapter mViewPagerAdapter;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.my_friends);
		setupViews();
		int position = getIntent().getIntExtra(Constants.EXTRA_POSITION, 0);
		mViewPager.setCurrentItem(position);
		setTitle(R.string.my_friends);
	}

	private void setupViews() {
		mViewPager = (ViewPager) findViewById(R.id.viewpager);
		mViewPager.setOffscreenPageLimit(1);
		mViewPagerAdapter = getAdapter();
		mViewPager.setAdapter(mViewPagerAdapter);
		mIndicator = (TabPageIndicator) findViewById(R.id.indicator);
		mIndicator.setViewPager(mViewPager);
	}

	private ViewPagerAdapter getAdapter() {
		ViewPagerAdapter adapter = new ViewPagerAdapter(getSupportFragmentManager(), this);
		adapter.addPager(getString(R.string.follow), FollowsFragment.class.getName(), new Bundle());
		adapter.addPager(getString(R.string.fans), FansFragment.class.getName(), new Bundle());
		return adapter;
	}
}
